package main

import (
	"fmt"
	"github.com/ethereum/go-ethereum/rpc"
)

func main() {

	//client, err := ethclient.Dial("https://kovan.infura.io/v3/18eb87a319f44408b7051d3a8e107d6e")
	//if err != nil {
	//	fmt.Println("获取余额失败", err)
	//}
	//fmt.Println("连接成功！")
	//account := common.HexToAddress("0x87904e4C63d5f388C95aDE6f1dEC01B0E82a4360")
	//blockNumber := big.NewInt(5532993)
	//balance, err := client.BalanceAt(context.Background(), account, blockNumber)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//var fbalance *big.Float = &big.Float{}
	////fbalance := new(big.Float)
	//fbalance.SetString(balance.String())
	//ethValue := new(big.Float).Quo(fbalance, big.NewFloat(math.Pow10(18)))
	//fmt.Println("账户余额 = ", ethValue)

	//bNumber, err := client.BlockNumber(context.Background())
	//if err != nil{
	//	log.Fatal(err)
	//}
	//fmt.Println(bNumber)
	//
	client2, err := rpc.Dial("https://node.lingjingchain.cn")
	if err != nil {
		fmt.Println("RPC接口错误", err)
	}
	var amount string
	err = client2.Call(&amount, "eth_getBalance", "0xd75DF457c12AA5f3B7f930998CfAb506E134247D", "latest")
	if err != nil {
		fmt.Println("获取余额失败", err)
	}
	fmt.Println(amount)

}

//func getBalance(address string) (string, error) {
//	client, err := rpc.Dial("https://ropsten.infura.io/v3/7cc738ff312f40c4988e78e05f2ab2fe")
//	if err != nil {
//		fmt.Println("RPC接口错误", err)
//		return "", err
//	}
//	var amount string
//	err = client.Call(&amount, "eth_getBalance", address, "latest")
//	if err != nil {
//		fmt.Println("获取余额失败", err)
//		return "", err
//	}
//	return amount, nil
//}
